package main

import "fmt"

// for-range
func main() {

	//这种构建方法可以应用于数组和切片
	//第一个返回值 ix 是数组或者切片的索引，第二个是在该索引位置的值；他们都是仅在 for 循环内部可见的局部变量
	//for ix, value := range slice1 {
	//    ...
	//}
	var slice1 = make([]int, 4)
	slice1[0] = 1
	slice1[1] = 2
	slice1[2] = 3
	slice1[3] = 4

	for ix, value := range slice1 {
		fmt.Printf("Slice at %d is: %d\n", ix, value)
	}

	seasons := []string{"Spring", "Summer", "Autumn", "Winter"}

	for ix, season := range seasons { //这里的ix 和 iv可以自定义
		fmt.Printf("Season %d is: %s\n", ix, season)

		var season string
		for _, season = range seasons {
			fmt.Printf("%s\n", season)
		}
	}

	for ix := range seasons { //如果你只需要索引，你可以忽略第二个变量
		fmt.Printf("%d", ix)
	}
}
